package top.caoayu.tools.db;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

public class OracleDocumentGeneration {
    private static final EngineFileType fileType = EngineFileType.HTML;
    private static final String outputDir = "./doc";
    private static final String schemaName = "T7_ORACLE";

    public static void main(String[] args) {
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("oracle.jdbc.OracleDriver");
        hikariConfig.setJdbcUrl("jdbc:oracle:thin:@//62.234.123.49:1521/chemdb.thinks.net.cn");
        hikariConfig.setUsername(schemaName);
        hikariConfig.setPassword("thinks5567");
        //设置可以获取tables remarks信息
        hikariConfig.addDataSourceProperty(schemaName, "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);

        EngineConfig engineConfig = EngineConfig.builder()
                .fileOutputDir(outputDir)
                .openOutputDir(true)
                .fileType(fileType)
                .produceType(EngineTemplateType.freemarker)
                .fileName(schemaName)
                .build();
        ProcessConfig processConfig = ProcessConfig.builder()
                .designatedTableName(new ArrayList<>())
                .designatedTablePrefix(new ArrayList<>())
                .designatedTableSuffix(new ArrayList<>())
                .ignoreTableName(new ArrayList<>())
                .ignoreTablePrefix(new ArrayList<>())
                .ignoreTableSuffix(new ArrayList<>())
                .build();
        Configuration config = Configuration.builder()
                .version("1.0")
                .description(schemaName + "-文档更新时间：" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
                .dataSource(dataSource)
                .engineConfig(engineConfig)
                .produceConfig(processConfig)
                .build();
        new DocumentationExecute(config).execute();

    }
}
